package com.huaxin.hxenum.enums;

import com.baomidou.mybatisplus.annotation.EnumValue;
import com.fasterxml.jackson.annotation.JsonValue;
import com.huaxin.hxenum.base.BaseCodeEnum;

/**
 * 数据质量枚举
 */
public enum DataQuality implements BaseCodeEnum<String> {

    NORMAL("normal", "正常"),
    OVER_LIMIT("over_limit", "超限"),
    OFFLINE("offline", "离线"),
    ABNORMAL("abnormal", "异常");

    @EnumValue
    private final String code;
    private final String displayName;

    DataQuality(String code, String displayName) {
        this.code = code;
        this.displayName = displayName;
    }

    @JsonValue
    @Override
    public String getCode() {
        return code;
    }

    @Override
    public String getDisplayName() {
        return displayName;
    }

    /**
     * 根据 code 获取枚举实例
     */
    public static DataQuality of(String code) {
        if (code == null || code.trim().isEmpty()) return null;
        for (DataQuality type : values()) {
            if (type.getCode().equalsIgnoreCase(code.trim())) {
                return type;
            }
        }
        return null;
    }

    /**
     * 判断是否为有效值
     */
    public static boolean isValid(String code) {
        return of(code) != null;
    }
}
